import socket

server_sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip_port = ('127.0.0.1', 9999)
server_sk.bind(ip_port)
server_sk.listen(128)

new_socket, addr = server_sk.accept()
while True:
    ret = new_socket.recv(1024).decode('utf-8')
    print('客户端发送来了消息:', ret)
    if ret == 'bye':
        break

    # 向客户端发送内容
    content = input('>>>')
    new_socket.send(content.encode('utf-8'))
    if content == 'bye':
        break

new_socket.close()
server_sk.close()
